package nl.haemers.buttons
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import nl.haemers.base.BaseSprite;
	
	/**
	 * @author Jonathan Haemers
	  */
	public class MovieButton extends BaseButton
	{
		public static const SELECTED		:String = "selected";
		public static const ROLL_OVER		:String = "rollOver";
		public static const ROLL_OUT		:String = "rollOut";
		public static const DOWN			:String = "down";
		public static const UP				:String = "up";
		
		protected var _state				:String;
		
		protected var hitAreaMC				:MovieClip;
		
		public function MovieButton() 
		{
			super();
		}
		
		/** Public methods **/
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		override protected function startup() : void
		{
			hitArea = new BaseSprite();
			
			getHitAreaFromStage();
			if (!hitAreaMC)
			{
				createHitArea();
			}
			
			configButton();
			configListeners();
		}
		
		override protected function configListeners() : void
		{
			super.configListeners();
			if (_enabled)
			{
				hitArea.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
				hitArea.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);			
			}
		}
		
		override protected function getHitAreaFromStage() : void
		{
			hitAreaMC = getChildByName("mcHitArea") as MovieClip;
		}
		
		override protected function clickHandler(e:MouseEvent) : void
		{
			gotoAndPlay(SELECTED);
		}
		
		override protected function rollOverHandler(e:MouseEvent) : void
		{
			gotoAndPlay(ROLL_OVER);
		}
		
		override protected function rollOutHandler(e:MouseEvent) : void
		{
			gotoAndPlay(ROLL_OUT);
		}
		
		protected function mouseDownHandler(e:MouseEvent) : void
		{
			gotoAndPlay(DOWN);
		}
		
		protected function mouseUpHandler(e:MouseEvent) : void
		{
			gotoAndPlay(UP);
		}
	}

}